﻿// ***********************************************************************
// Provided for Informational Purposes Only
//
// Apache 2.0 License
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Api.WinRT
// File      : MessageClient.cs
//
// ***********************************************************************

using ContractMeow.Api.Dtos;
using ContractMeow.Data.WinRT.Models;
using ContractMeow.WinRT.Serialization;
using Newtonsoft.Json.Linq;
using System.Net;
using System.Threading.Tasks;

namespace ContractMeow.Api.Clients
{
	/// <summary>
	/// Class OpenGraphClient
	/// This class helps submitting activities in the form of open graph objects to the yammer api.
	/// </summary>
	public class MessageClient : ClientBase, IMessageClient
	{
		/// <summary>
		/// The URL
		/// </summary>
		private const string url = "/api/v1/messages.json";
		/// <summary>
		/// Initializes a new instance of the <see cref="ClientBase" /> class.
		/// </summary>
		/// <param name="configuration">The configuration.</param>
		/// <param name="queryStringSerializer">The query string serializer.</param>
		/// <param name="serializer">The serializer.</param>
		/// <param name="deserializer">The deserializer.</param>
		/// <param name="responseErrorHandler">The response error handler.</param>
		/// <param name="cookieStore">The cookie store.</param>
		/// <param name="proxy">The proxy.</param>
		public MessageClient(IClientConfiguration configuration,
								IQueryStringSerializer queryStringSerializer,
								ISerializer serializer,
								IDeserializer deserializer,
								IResponseErrorHandler responseErrorHandler,
								ICookieStore cookieStore,
								IWebProxy proxy = null)
			: base(configuration, queryStringSerializer, serializer, deserializer, responseErrorHandler, cookieStore, proxy)
		{ }

		/// <summary>
		/// Submits the activity (Open Graph Object) to yammer asynchronously.
		/// </summary>
		/// <param name="credentials">The credentials.</param>
		/// <param name="activity">The activity.</param>
		/// <returns>Task.</returns>
		public async Task<MessageEnvelope> PostMessageAsync(Principal credentials, MessageObject message)
		{
			VerifyCredentials(credentials);

			var r = await PostAsync<MessageEnvelope>(url, credentials, message);
			return r.Result();
		}


	}
}